using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;

namespace Commerce.Common
{
    /// <summary>
    /// Controller class for CSK_Store_Order
    /// </summary>
    [System.ComponentModel.DataObject]
    public partial class OrderController
    {
        // Preload our schema..
        Order thisSchemaLoad = new Order();
        private string userName = string.Empty;
        protected string UserName
        {
            get
            {
				if (userName.Length == 0) 
				{
    				if (System.Web.HttpContext.Current != null)
    				{
						userName=System.Web.HttpContext.Current.User.Identity.Name;
					}

					else
					{
						userName=System.Threading.Thread.CurrentPrincipal.Identity.Name;
					}

				}

				return userName;
            }

        }

        [DataObjectMethod(DataObjectMethodType.Select, true)]
        public OrderCollection FetchAll()
        {
            OrderCollection coll = new OrderCollection();
            Query qry = new Query(Order.Schema);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Select, false)]
        public OrderCollection FetchByID(object OrderID)
        {
            OrderCollection coll = new OrderCollection().Where("orderID", OrderID).Load();
            return coll;
        }

		
		[DataObjectMethod(DataObjectMethodType.Select, false)]
        public OrderCollection FetchByQuery(Query qry)
        {
            OrderCollection coll = new OrderCollection();
            coll.LoadAndCloseReader(qry.ExecuteReader()); 
            return coll;
        }

        [DataObjectMethod(DataObjectMethodType.Delete, true)]
        public bool Delete(object OrderID)
        {
            return (Order.Delete(OrderID) == 1);
        }

        [DataObjectMethod(DataObjectMethodType.Delete, false)]
        public bool Destroy(object OrderID)
        {
            return (Order.Destroy(OrderID) == 1);
        }

        
        
    	
	    /// <summary>
	    /// Inserts a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Insert, true)]
	    public void Insert(string OrderGUID,string OrderNumber,DateTime OrderDate,int OrderStatusID,string UserName,string Email,string FirstName,string LastName,string ShipPhone,string ShippingMethod,decimal SubTotalAmount,decimal ShippingAmount,decimal HandlingAmount,decimal TaxAmount,decimal TaxRate,string CouponCodes,decimal DiscountAmount,string SpecialInstructions,string ShipToAddress,string BillToAddress,string UserIP,string ShippingTrackingNumber,int NumberOfPackages,string PackagingNotes,DateTime CreatedOn,string CreatedBy,DateTime ModifiedOn,string ModifiedBy)
	    {
		    Order item = new Order();
		    
            item.OrderGUID = OrderGUID;
            
            item.OrderNumber = OrderNumber;
            
            item.OrderDate = OrderDate;
            
            item.OrderStatusID = OrderStatusID;
            
            item.UserName = UserName;
            
            item.Email = Email;
            
            item.FirstName = FirstName;
            
            item.LastName = LastName;
            
            item.ShipPhone = ShipPhone;
            
            item.ShippingMethod = ShippingMethod;
            
            item.SubTotalAmount = SubTotalAmount;
            
            item.ShippingAmount = ShippingAmount;
            
            item.HandlingAmount = HandlingAmount;
            
            item.TaxAmount = TaxAmount;
            
            item.TaxRate = TaxRate;
            
            item.CouponCodes = CouponCodes;
            
            item.DiscountAmount = DiscountAmount;
            
            item.SpecialInstructions = SpecialInstructions;
            
            item.ShipToAddress = ShipToAddress;
            
            item.BillToAddress = BillToAddress;
            
            item.UserIP = UserIP;
            
            item.ShippingTrackingNumber = ShippingTrackingNumber;
            
            item.NumberOfPackages = NumberOfPackages;
            
            item.PackagingNotes = PackagingNotes;
            
            item.CreatedOn = CreatedOn;
            
            item.CreatedBy = CreatedBy;
            
            item.ModifiedOn = ModifiedOn;
            
            item.ModifiedBy = ModifiedBy;
            
	    
		    item.Save(UserName);
	    }

    	
	    /// <summary>
	    /// Updates a record, can be used with the Object Data Source
	    /// </summary>
        [DataObjectMethod(DataObjectMethodType.Update, true)]
	    public void Update(int OrderID,string OrderGUID,string OrderNumber,DateTime OrderDate,int OrderStatusID,string UserName,string Email,string FirstName,string LastName,string ShipPhone,string ShippingMethod,decimal SubTotalAmount,decimal ShippingAmount,decimal HandlingAmount,decimal TaxAmount,decimal TaxRate,string CouponCodes,decimal DiscountAmount,string SpecialInstructions,string ShipToAddress,string BillToAddress,string UserIP,string ShippingTrackingNumber,int NumberOfPackages,string PackagingNotes,DateTime CreatedOn,string CreatedBy,DateTime ModifiedOn,string ModifiedBy)
	    {
		    Order item = new Order();
		    
				item.OrderID = OrderID;
				
				item.OrderGUID = OrderGUID;
				
				item.OrderNumber = OrderNumber;
				
				item.OrderDate = OrderDate;
				
				item.OrderStatusID = OrderStatusID;
				
				item.UserName = UserName;
				
				item.Email = Email;
				
				item.FirstName = FirstName;
				
				item.LastName = LastName;
				
				item.ShipPhone = ShipPhone;
				
				item.ShippingMethod = ShippingMethod;
				
				item.SubTotalAmount = SubTotalAmount;
				
				item.ShippingAmount = ShippingAmount;
				
				item.HandlingAmount = HandlingAmount;
				
				item.TaxAmount = TaxAmount;
				
				item.TaxRate = TaxRate;
				
				item.CouponCodes = CouponCodes;
				
				item.DiscountAmount = DiscountAmount;
				
				item.SpecialInstructions = SpecialInstructions;
				
				item.ShipToAddress = ShipToAddress;
				
				item.BillToAddress = BillToAddress;
				
				item.UserIP = UserIP;
				
				item.ShippingTrackingNumber = ShippingTrackingNumber;
				
				item.NumberOfPackages = NumberOfPackages;
				
				item.PackagingNotes = PackagingNotes;
				
				item.CreatedOn = CreatedOn;
				
				item.CreatedBy = CreatedBy;
				
				item.ModifiedOn = ModifiedOn;
				
				item.ModifiedBy = ModifiedBy;
				
		    item.MarkOld();
		    item.Save(UserName);
	    }

    }

}

